package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.TextbookOrder;
import com.hwadee.teachingprocessmanagementsystem.dao.TextbookOrderDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.TextbookOrderService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * 教材征订表(TextbookOrder)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:03
 */
@Service("textbookOrderService")
public class TextbookOrderServiceImpl implements TextbookOrderService {
    @Resource
    private TextbookOrderDao textbookOrderDao;

    /**
     * 通过ID查询单条数据
     *
     * @param orderId 主键
     * @return 实例对象
     */
    @Override
    public TextbookOrder queryById(Integer orderId) {
        return this.textbookOrderDao.queryById(orderId);
    }

    /**
     * 分页查询
     *
     * @param textbookOrder 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TextbookOrder> queryByPage(TextbookOrder textbookOrder, PageRequest pageRequest) {
        long total = this.textbookOrderDao.count(textbookOrder);
        return new PageImpl<>(this.textbookOrderDao.queryAllByLimit(textbookOrder, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param textbookOrder 实例对象
     * @return 实例对象
     */
    @Override
    public TextbookOrder insert(TextbookOrder textbookOrder) {
        this.textbookOrderDao.insert(textbookOrder);
        return textbookOrder;
    }

    /**
     * 修改数据
     *
     * @param textbookOrder 实例对象
     * @return 实例对象
     */
    @Override
    public TextbookOrder update(TextbookOrder textbookOrder) {
        this.textbookOrderDao.update(textbookOrder);
        return this.queryById(textbookOrder.getOrderId());
    }

    /**
     * 通过主键删除数据
     *
     * @param orderId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer orderId) {
        return this.textbookOrderDao.deleteById(orderId) > 0;
    }
}
